using System;
using System.Collections.Generic;
using System.Text;

namespace Coriander.Google.Services.Authentication
{
    /// <summary>
    /// See: http://dystopics.dump.be/2006/02/04/the-mysteries-of-x-google-token-and-why-it-matters/
    /// </summary>
    public class XGoogleToken
    {
        private readonly String value;

        /// <summary>
        /// An empty token
        /// </summary>
        public static readonly XGoogleToken Empty = new XGoogleToken(null, null);  

        /// <summary>
        /// The value of the token
        /// </summary>
        public String Value
        {
            get { return this.value; }
        }

        /// <summary>
        /// ctor: String, String
        /// </summary>
        /// <param name="username"></param>
        /// <param name="token"></param>
        public XGoogleToken(String username, String token)
        {
            value = Convert.ToBase64String(
                Encoding.UTF8.GetBytes(
                    String.Format(
                        "\0{0}\0{1}",
                        username,
                        token
                    )
                )
            );
        }
    }
}
